#include "../common/message.hpp"
#include "../common/net.hpp"
#include <thread>

void onMessage(const rpc::BaseConnection::ptr& conn,rpc::BaseMessage::ptr &msg)
{
    std::string body = msg->serialize();
    std::cout << body << std::endl;
}

int main()
{
    auto client = rpc::CilentFactory::create("127.0.0.1",9090);
    client->setMessageCallback(onMessage);
    client->connect();
    auto rpc_req = rpc::MessageFactory::create<rpc::RpcRequest>();
    rpc_req->setid("123");
    rpc_req->setmtype(rpc::Mtype::REQ_RPC);
    Json::Value val;
    val["num1"] = 11;
    val["num2"] = 22;
    rpc_req->setParams(val);
    rpc_req->setMethod("Add");
    client->send(rpc_req);
    std::this_thread::sleep_for(std::chrono::seconds(10));
    client->shutdown(); 
    return 0;
}